package jp.tkym.labs.client.geom;

public class Vector3f {
	float x, y, z;
	
	Vector3f(){
		this(0.0f, 0.0f, 0.0f);
	}
	
	Vector3f(float x, float y, float z){
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	Vector3f diff(Vector3f a){
		this.x -= a.x;
		this.y -= a.y;
		this.z -= a.z;
		return this;
	}
	
	Vector3f add(Vector3f a){
		this.x += a.x;
		this.y += a.y;
		this.z += a.z;
		return this;
	}
	
	float inner(Vector3f a){
		return this.x*a.x + this.y*a.y + this.z * a.z;
	}
	
	protected Vector3f clone(){
		return new Vector3f(this.x, this.y, this.z);
	}
	
	Vector3f multiply(Matrix3f left){
		Vector3f r  = this.clone();
		this.x = left.getRow(0).inner(r);
		this.y = left.getRow(1).inner(r);
		this.z = left.getRow(2).inner(r);
		return this;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(x);
		result = prime * result + Float.floatToIntBits(y);
		result = prime * result + Float.floatToIntBits(z);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Vector3f other = (Vector3f) obj;
		if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
			return false;
		if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
			return false;
		if (Float.floatToIntBits(z) != Float.floatToIntBits(other.z))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "[" + x + ", " + y + ", " + z + "]";
	}
}